package com.hudson.namesrv.config;

import com.hudson.core.util.PropertiesUtil;
import com.hudson.namesrv.util.InetAddressUtil;

import java.net.InetAddress;
import java.util.Optional;
import java.util.Properties;

public class NameSrvConfig {
    public static int bossThreads;
    public static int workerThreads;
    public static String address;
    public static int port;
    public static int serializableMethod;

    static {
        Properties prop = PropertiesUtil.getProperties("NameSrvConfig.properties");


        bossThreads = Integer.parseInt(prop.getProperty("bossThreads", "2"));
        workerThreads = Integer.parseInt(prop.getProperty("workerThreads", "4"));
        address = String.valueOf(prop.getProperty("address",
                Optional.ofNullable(InetAddressUtil.get()).map(InetAddress::getHostAddress).orElse("127.0.0.1")));
        port = Integer.parseInt(prop.getProperty("port", "8080"));

        serializableMethod = Integer.parseInt(prop.getProperty("serializableMethod", String.valueOf(0)));
    }
}
